package Zoo.util;

import lesson05.utils.JdbcUtils_DBCP;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * 注册用户时对应的工具类
 */


public class InsertUtil {

    public void insert(String name, String password, String phone) {
        Connection conn = null;
        PreparedStatement st = null;


        try {
            conn = JdbcUtils_DBCP.getConnection();
            String sql = "INSERT INTO `users` (`name`,`password`,`phone`)VALUES (?,?,?)";

            st = conn.prepareStatement(sql);

            st.setString(1, name);
            st.setString(2, password);
            st.setString(3, phone);


            int i = st.executeUpdate();

            if (i > 0) {
                System.out.println("插入成功");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            JdbcUtils_DBCP.release(conn, st, null);
        }
    }
}
